package com.test.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONObject;
import com.test.controller.pojo.TestBaoxuanVO;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName BaoxuanController
 * @Description
 * @Author Zhang Li Tao
 * @Date 2023/7/3 16:32
 * @Version 1.0
 **/
@RestController // 将实体类转换为json
@RequestMapping("baoxuan") // 当前Controller中 所有接口的 统一路径
public class BaoxuanController {
    @GetMapping("testGet")
    public TestBaoxuanVO test1() {

        TestBaoxuanVO testBaoxuanVO = new TestBaoxuanVO();

        testBaoxuanVO.setAge("15");
        testBaoxuanVO.setCity("金华");
        testBaoxuanVO.setName("轩宝");

        return testBaoxuanVO;
    }

    @GetMapping("testGet2")
    public List<TestBaoxuanVO> test2() {
        List<TestBaoxuanVO> list = CollUtil.newArrayList();

        TestBaoxuanVO testBaoxuanVO = new TestBaoxuanVO();
        testBaoxuanVO.setAge("15");
        testBaoxuanVO.setCity("金华");
        testBaoxuanVO.setName("轩宝");


        TestBaoxuanVO testBaoxuanVO1 = new TestBaoxuanVO();
        testBaoxuanVO1.setAge("16");
        testBaoxuanVO1.setCity("金华1");
        testBaoxuanVO1.setName("轩宝1");

        list.add(testBaoxuanVO);
        list.add(testBaoxuanVO1);

        return list;
    }



    @GetMapping("testGet3")
    public List<TestBaoxuanVO> test3(@RequestParam(required = false, defaultValue = "15") String age) {
        List<TestBaoxuanVO> list = CollUtil.newArrayList();

        TestBaoxuanVO testBaoxuanVO = new TestBaoxuanVO();
        testBaoxuanVO.setAge("15");
        testBaoxuanVO.setCity("金华");
        testBaoxuanVO.setName("轩宝");

        TestBaoxuanVO testBaoxuanVO1 = new TestBaoxuanVO();
        testBaoxuanVO1.setAge("16");
        testBaoxuanVO1.setCity("金华1");
        testBaoxuanVO1.setName("轩宝1");

        list.add(testBaoxuanVO);
        list.add(testBaoxuanVO1);

        return list.stream().filter(u -> u.getAge().equals(age)).collect(Collectors.toList());
    }


    @PostMapping("testGet4")
    public Map<String, Object> test4(@RequestBody TestBaoxuanVO vo) {

        Map<String, Object> resultMap = MapUtil.newHashMap();

        resultMap.put("code", 200);
        resultMap.put("msg", "新增客户成功");
        resultMap.put("data", vo);

        return resultMap;
    }

    @PostMapping("testGet5")
    public Map<String, Object> test5(@RequestBody TestBaoxuanVO vo) {
        List<TestBaoxuanVO> list = CollUtil.newArrayList();
        list.add(vo);

        Map<String, Object> dataMap = MapUtil.newHashMap();
        dataMap.put("data", list);
        dataMap.put("msg", "插入成功");

        Map<String, Object> resultMap = MapUtil.newHashMap();
        resultMap.put("code", 200);
        resultMap.put("msg", "新增客户成功");
        resultMap.put("data", dataMap);


        return resultMap;
    }


    @GetMapping("testGet6")
    public JSONObject test6() {
        String str = "{\n" +
                "    \"msg\": \"\",\n" +
                "    \"total\": 2,\n" +
                "    \"code\": \"\",\n" +
                "    \"data\": [\n" +
                "        {\n" +
                "            \"uuid\": \"137e48b2-5a24-40b7-90f0-732fb05fb8af\",\n" +
                "            \"name\": \"HXSCQ-KONG\",\n" +
                "            \"description\": \"青岛医保核心生产区服务网关\",\n" +
                "            \"openService\": \"0\",\n" +
                "            \"approval\": \"disable\",\n" +
                "            \"projectId\": \"5733bae3343247fe938fd3cbe6343986\",\n" +
                "            \"userId\": \"523e8843b29e4df386615e35a98e15b4\",\n" +
                "            \"serviceType\": \"svcgw\",\n" +
                "            \"serviceVersion\": \"1.0\",\n" +
                "            \"kongIp\": \"10.78.248.137/27,10.78.248.138/27,10.78.248.139/27\",\n" +
                "            \"kongHttpProxyPort\": \"48000,48000,48000\",\n" +
                "            \"kongHttpsProxyPort\": \"48443,48443,48443\",\n" +
                "            \"status\": \"RUNNING\",\n" +
                "            \"metadata\": null,\n" +
                "            \"resourceType\": \"CONTAINER\",\n" +
                "            \"namespace\": \"svcgw83ece7ca\",\n" +
                "            \"releaseName\": \"svcgw018b6885\",\n" +
                "            \"svcApimgtName\": \"10.78.248.129:32107\",\n" +
                "            \"svcKonjacName\": \"svcgw83ece7ca-svcgw018b6885-konjac-svc.svcgw83ece7ca.svc\",\n" +
                "            \"svcKongName\": \"svcgw83ece7ca-svcgw018b6885-kong-admin-svc.svcgw83ece7ca.svc\",\n" +
                "            \"svcDbName\": \"svcgw83ece7ca-svcgw018b6885-psql-svc.svcgw83ece7ca.svc\",\n" +
                "            \"k8sClusterId\": \"559740AD-F0C2-4C18-B34\",\n" +
                "            \"k8sClusterVip\": \"10.78.248.129\",\n" +
                "            \"createTime\": \"2021-10-23T08:03:12.000+0000\",\n" +
                "            \"updateTime\": \"2023-06-24T17:50:13.000+0000\",\n" +
                "            \"zoneId\": \"b5bc9655-9\",\n" +
                "            \"zoneName\": \"HXSCQ-WORKER\",\n" +
                "            \"projectName\": \"QDYB-HXSCQ\",\n" +
                "            \"userName\": \"hxscq-admin\",\n" +
                "            \"resource\": \"{\\\"limits\\\":{\\\"cpu\\\":\\\"16\\\",\\\"memory\\\":\\\"32Gi\\\"},\\\"requests\\\":{\\\"cpu\\\":\\\"4\\\",\\\"memory\\\":\\\"8Gi\\\"}}\",\n" +
                "            \"pvcType\": \"dynamic\",\n" +
                "            \"storageClass\": \"hxscq-kong\",\n" +
                "            \"dataVolume\": \"50Gi\",\n" +
                "            \"replicas\": 3,\n" +
                "            \"volumeName\": \"pvc-bd76b793-33d7-11ec-b4c3-0cda411d5b34\",\n" +
                "            \"clusterType\": \"PUBLIC_ZONE\",\n" +
                "            \"clusterPort\": \"8443\",\n" +
                "            \"privateKaasName\": null\n" +
                "        },\n" +
                "        {\n" +
                "            \"uuid\": \"af8fbc31-8374-4efa-9e38-63dddbf56f18\",\n" +
                "            \"name\": \"HXCSQ-KONG\",\n" +
                "            \"description\": \"青岛医保核心业务区测试区服务网关\",\n" +
                "            \"openService\": \"0\",\n" +
                "            \"approval\": \"disable\",\n" +
                "            \"projectId\": \"fefaa529ed1c4ec0bce921e1d836a90b\",\n" +
                "            \"userId\": \"9967e2c8216049b49e7998e46c0f04a1\",\n" +
                "            \"serviceType\": \"svcgw\",\n" +
                "            \"serviceVersion\": \"1.0\",\n" +
                "            \"kongIp\": \"10.78.253.235/28,10.78.253.236/28,10.78.253.237/28\",\n" +
                "            \"kongHttpProxyPort\": \"48000,48000,48000\",\n" +
                "            \"kongHttpsProxyPort\": \"48443,48443,48443\",\n" +
                "            \"status\": \"RUNNING\",\n" +
                "            \"metadata\": null,\n" +
                "            \"resourceType\": \"CONTAINER\",\n" +
                "            \"namespace\": \"svcgwae51d2c3\",\n" +
                "            \"releaseName\": \"svcgw9b1b1df6\",\n" +
                "            \"svcApimgtName\": \"10.78.253.230:32252\",\n" +
                "            \"svcKonjacName\": \"svcgwae51d2c3-svcgw9b1b1df6-konjac-svc.svcgwae51d2c3.svc\",\n" +
                "            \"svcKongName\": \"svcgwae51d2c3-svcgw9b1b1df6-kong-admin-svc.svcgwae51d2c3.svc\",\n" +
                "            \"svcDbName\": \"svcgwae51d2c3-svcgw9b1b1df6-psql-svc.svcgwae51d2c3.svc\",\n" +
                "            \"k8sClusterId\": \"3FC920B5-048E-4AC9-8E5\",\n" +
                "            \"k8sClusterVip\": \"10.78.253.230\",\n" +
                "            \"createTime\": \"2021-10-23T08:45:39.000+0000\",\n" +
                "            \"updateTime\": \"2023-06-24T11:50:11.000+0000\",\n" +
                "            \"zoneId\": \"afad5c8a-0\",\n" +
                "            \"zoneName\": \"HXCSQ-WORKER\",\n" +
                "            \"projectName\": \"QDYB-HXCSQ\",\n" +
                "            \"userName\": \"hxcsq-admin\",\n" +
                "            \"resource\": \"{\\\"limits\\\":{\\\"cpu\\\":\\\"16\\\",\\\"memory\\\":\\\"32Gi\\\"},\\\"requests\\\":{\\\"cpu\\\":\\\"4\\\",\\\"memory\\\":\\\"8Gi\\\"}}\",\n" +
                "            \"pvcType\": \"dynamic\",\n" +
                "            \"storageClass\": \"hxcsq-kong\",\n" +
                "            \"dataVolume\": \"50Gi\",\n" +
                "            \"replicas\": 3,\n" +
                "            \"volumeName\": \"pvc-bf368b98-33dd-11ec-8e53-0cda411d1667\",\n" +
                "            \"clusterType\": \"PUBLIC_ZONE\",\n" +
                "            \"clusterPort\": \"8443\",\n" +
                "            \"privateKaasName\": null\n" +
                "        }\n" +
                "    ],\n" +
                "    \"status\": true\n" +
                "}";

        return new JSONObject(str);
    }

}
